using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DropGame : MonoBehaviour
{
    public Transform ground;

    public Transform target;

    // Update is called once per frame
    void Update()
    {
        Vector3 camDir = Camera.main.ScreenPointToRay(Input.mousePosition).direction.normalized;

        Vector3 groundNormal = ground.up;

        Vector3 cam2GroundDir = ground.transform.position - Camera.main.transform.position;

        float len = (cam2GroundDir.x * groundNormal.x + cam2GroundDir.y * groundNormal.y +
                     cam2GroundDir.z * groundNormal.z) / (camDir.x * groundNormal.x + camDir.y * groundNormal.y +
                                                          camDir.z * groundNormal.z);

        Vector3 targetPos = Camera.main.transform.position + camDir * len+new Vector3(0,0.5f,0);

        target.transform.position = targetPos;
    }
}